import { Column, CreateDateColumn, Entity, Index, OneToMany, PrimaryGeneratedColumn, UpdateDateColumn } from 'typeorm';
import { Article } from '../../articles/entities/article.entity';

@Entity()
@Index(['tree'])
export class Category {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({
    type: 'varchar',
    length: 128,
    comment: '分类名(竖线分隔层级)',
    unique: true,
  })
  tree: string;

  @Column({ type: 'int', default: 0, comment: '排序优先级 越小越前' })
  sort: number;

  @OneToMany(() => Article, (article) => article.category)
  articles: Article[];

  @CreateDateColumn()
  createTime: Date;

  @UpdateDateColumn()
  updateTime: Date;
}
